package com.company.majiang.proto;

import java.io.IOException;

import com.company.majiang.isnowfox.AbstractMessage;
import com.company.majiang.isnowfox.Input;
import com.company.majiang.isnowfox.Output;
import com.company.majiang.isnowfox.ProtocolException;

public class RoomHistoryListRet extends AbstractMessage {
	public static final int TYPE = 7;
	public static final int ID = 20;

	private java.util.ArrayList<RoomHistory> list;

	public RoomHistoryListRet() {

	}

	public RoomHistoryListRet(java.util.ArrayList<RoomHistory> list) {
		this.list = list;
	}

	@Override
	public void decode(Input in) throws IOException, ProtocolException {

		int listLen = in.readInt();
		if (listLen == -1) {
			list = null;
		} else {
			list = new java.util.ArrayList<RoomHistory>(listLen);
			for (int i = 0; i < listLen; i++) {
				RoomHistory listItem = new RoomHistory();
				listItem.decode(in);
				list.add(listItem);
			}
		}
	}

	@Override
	public void encode(Output out) throws IOException, ProtocolException {

		if (list == null) {
			out.writeInt(-1);
		} else {
			java.util.ArrayList<RoomHistory> listList = getList();
			int listLen = listList.size();
			out.writeInt(listLen);
			for (RoomHistory listItem : listList) {
				listItem.encode(out);
			}
		}
	}

	public java.util.ArrayList<RoomHistory> getList() {
		return list;
	}

	public void setList(java.util.ArrayList<RoomHistory> list) {
		this.list = list;
	}

	public void addList(RoomHistory list) {
		if (this.list == null) {
			this.list = new java.util.ArrayList<RoomHistory>();
		}
		this.list.add(list);
	}

	@Override
	public String toString() {
		return "RoomHistoryListRet [list=" + list + ", ]";
	}

	@Override
	public final int getMessageType() {
		return TYPE;
	}

	@Override
	public final int getMessageId() {
		return ID;
	}
}
